package com.koron.order.overhaul.service.impl;

import com.koron.common.core.util.CodeTools;
import com.koron.order.overhaul.bean.entity.OverhaulOrderReportBean;
import com.koron.order.overhaul.mapper.OverhaulOrderReportMapper;
import com.koron.order.overhaul.service.OverhaulOrderReportService;
import com.koron.order.overhaul.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.springframework.stereotype.Service;

/**
 * (OverhaulOrderReportBean)表服务实现类
 *
 * @author twcao
 * @since 2021-09-29 09:49:36
 */
@Service
public class OverhaulReportServiceImpl implements OverhaulOrderReportService {

    @Override
    public OverhaulOrderReportBean queryById(SessionFactory factory, String id) {
        OverhaulOrderReportMapper mapper = factory.getMapper(OverhaulOrderReportMapper.class);
        return mapper.queryById(id);
    }

    @Override
    public OverhaulOrderReportBean queryByOrderId(SessionFactory factory, String orderId) {
        OverhaulOrderReportMapper mapper = factory.getMapper(OverhaulOrderReportMapper.class);
        return mapper.queryByOrderId(orderId);
    }

    @Override
    public OverhaulOrderReportBean saveOrUpdate(SessionFactory factory, OverhaulOrderReportBean bean) {
        OverhaulOrderReportMapper mapper = factory.getMapper(OverhaulOrderReportMapper.class);
        bean.setId(StringUtils.isBlank(bean.getId()) ? CodeTools.getCode32() : bean.getId());
        CommonUtils.update(bean);
        mapper.saveOrUpdate(bean);
        return queryById(factory, bean.getId());
    }

    @Override
    public int deleteByOrderId(SessionFactory factory, String orderId) {
        OverhaulOrderReportMapper mapper = factory.getMapper(OverhaulOrderReportMapper.class);
        return mapper.deleteByOrderId(orderId);
    }
}
